<?php
declare(strict_types=1);

namespace app\validate;

use think\Validate;

class ExpressServiceProviderValidate extends Validate
{
    protected $rule = [
        'id' => 'require',
        'service_code' => 'require|unique:express_service_provider',
        'company_name' => 'require|max:50',
        'company_code' => 'require|max:20',
        'service_type' => 'require|max:50',
        'channel' => 'max:50',
        'description' => 'max:255',
        'weight_index' => 'require|float|gt:0',
        'first_weight' => 'require|float|gt:0',
        'min_weight' => 'require|float|gt:0',
        'max_weight' => 'require|float|gt:min_weight',
        'is_insured' => 'require|in:0,1',
        'insure_fee' => 'requireIf:is_insured,1|float|between:0,100',
        'status' => 'require|in:1,2'
    ];

    protected $message = [
        'service_code.require' => '服务商代码不能为空',
        'service_code.unique' => '服务商代码已存在',
        'company_name.require' => '公司名称不能为空',
        'company_name.max' => '公司名称最多50个字符',
        'company_code.require' => '快递公司代码不能为空',
        'company_code.max' => '快递公司代码最多20个字符',
        'service_type.require' => '服务类型不能为空',
        'service_type.max' => '服务类型最多50个字符',
        'channel.max' => '渠道信息最多50个字符',
        'description.max' => '描述信息最多255个字符',
        'weight_index.require' => '抛重系数不能为空',
        'weight_index.float' => '抛重系数必须为数字',
        'weight_index.gt' => '抛重系数必须大于0',
        'is_insured.require' => '请选择是否支持保价',
        'is_insured.in' => '是否支持保价参数错误',
        'insure_fee.requireIf' => '支持保价时保价费率不能为空',
        'insure_fee.float' => '保价费率必须为数字',
        'insure_fee.between' => '保价费率必须在0-100之间',
        'status.require' => '状态不能为空',
        'status.in' => '状态参数错误',
        'first_weight.require' => '首重不能为空',
        'first_weight.float' => '首重必须为数字',
        'first_weight.gt' => '首重必须大于0',
        'min_weight.require' => '最小可邮寄重量不能为空',
        'min_weight.float' => '最小可邮寄重量必须为数字',
        'min_weight.gt' => '最小可邮寄重量必须大于0',
        'max_weight.require' => '最大可邮寄重量不能为空',
        'max_weight.float' => '最大可邮寄重量必须为数字',
        'max_weight.gt' => '最大可邮寄重量必须大于最小可邮寄重量'
    ];

    // 添加场景
    public function sceneAdd()
    {
        return $this->only(['service_code','company_name','company_code','service_type','weight_index',
            'first_weight','min_weight','max_weight',
            'is_insured','insure_fee','merchant_profit_rate','platform_profit_rate'])
            ->append('service_code', 'unique:express_service_provider');
    }

    // 编辑场景
    public function sceneEdit()
    {
        return $this->only(['company_name','service_type','weight_index',
            'first_weight','min_weight','max_weight',
            'is_insured','insure_fee'])
            ->remove('service_code', 'unique');
    }

    // 设置状态场景
    public function sceneSetStatus()
    {
        return $this->only(['id','status']);
    }
} 